GBML manual / Audio

music_fading

True while a music_fade_to is still going on - the old song fading out, then the new one fading in - and false once the music has settled.

Syntax

music_fading() -> bool

Returns

bool

Description

Answers one yes-or-no question: is the music in the middle of a fade right now?

music_fade_to does not swap songs in one go. It turns the old song down until it is silent, then starts the new song at silence and turns it up. That is two halves, and music_fading is true for the whole time, both halves, and false for the rest of the time. It turns true on the very frame you call music_fade_to, and false again the moment the new song has reached its volume.

It is always false after music_play or music_stop, because those two change the music at once and never fade. It also stays false if you ask music_fade_to for the song that is already playing, since that call does nothing at all.

Why not just ask music_current? Because music_current tells you which song the music is heading for, not which one you can hear. The moment you call music_fade_to(song_cave, true, 1), music_current() says the cave song - while the old song is still playing and fading out for another quarter of a second. music_fading is how you tell "I asked for it" from "it has arrived": when music_current has changed and music_fading is still true, the change has not finished yet.

To see how far along the fade is, ask music_volume as well.

Example

if (music_fading()) {
    draw_text_anchored(ANCHOR_TOP_LEFT, 4, 4, "FADING");
}

Writes the word FADING in the top-left corner of the screen while the music is changing, and takes it away when the change is over. It is in a Draw GUI event, so it is checked again on every picture the game draws.

On the GBA

True from the very frame music_fade_to takes a change on, through both halves of the fade, until the music is at the volume it was asked for. Always false after music_play or music_stop, which never fade. music_current cannot tell you this: it names the song the music is heading for, which is the new song the instant you ask, while the old one can stay audible for another 16 frames.

See also: music_volumemusic_fade_tomusic_current